
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )

include( 'shared.lua' )


// Serverside only stuff goes here

/*---------------------------------------------------------
   Name: gamemode:PlayerLoadout( )
   Desc: Give the player the weapons I want to give
---------------------------------------------------------*/
--Sets settings for the player like Maximum Health, Gravity, etc
function GM:PlayerSpawn( ply )
       self.BaseClass:PlayerSpawn( ply )
       ply:SetGravity( 1, true )
       ply:SetMaxHealth( 60, true )
       ply:SetWalkSpeed( 100 )
       ply:SetRunSpeed( 200 )
     if ply:Team() == 1 then    
       ply:SetModel( "models/player/Group03/Male_07.mdl" )
     if ply:Team() == 2 then
     ply:SetModel( "models/player/combine_soldier.mdl" )
      end
   end
end

function GM:PlayerLoadout( ply )
          
   if ply:Team() == 1 then    
       ply:StripWeapons()
       ply:Give( "climb_swep" )         
       ply:Give( "weapon_SMG1" )
       end
   if ply:Team() == 2 then
       ply:StripWeapons ()
       ply:Give( "climb_swep" )
       ply:Give( "weapon_AR2" )
       end
end

--What will happen when the player first spawns
function GM:PlayerInitialSpawn( ply )
--Fixes errors for sandbox
       self.BaseClass:PlayerInitialSpawn( ply )
-- Show the team select menu defined in cl_int.
       RunConsoleCommand( "team_menu" )
--check if someone is an admin with an if statement
       if ply:IsAdmin() then

-- To print a message(*where* *what*) atm it goes to the players chatbox
       ply:PrintMessage( HUD_PRINTTALK, "SERVER: Your an admin, I can tell, I'm psychic" )
   end
end

--both a function (Gm.PlayerInitialSpawn) and an if statement (If ply:IsAdmin() then) need an end

--The roll ability
umsg.PoolString("Spin To")
AddCSLuaFile("autorun/client/roll.lua")

function RollPlayerSpawn(ply)
	ply.HasDoneARoll = false
end

hook.Add("PlayerSpawn", "RollPlayerSpawn", RollPlayerSpawn)

function PlayerLandsRoll(ply)
	if ply:EyeAngles().p >= 45 then
		if ply:KeyDown(IN_RELOAD) and ply:KeyDown(IN_DUCK) and ply:GetVelocityLength() <= 1100 then
			ply.HasDoneARoll = true
		end
	end
end

hook.Add("OnPlayerHitGround", "PlayerLandsRoll", PlayerLandsRoll)

function DoARoll(ent, inflictor, attacker, amount, dmginfo)
	if ent:IsPlayer() then
		if ent.HasDoneARoll == true then
			if (ent:Health() - (dmginfo:GetDamage() * 0.5)) > 0 then
				if dmginfo:IsFallDamage() then
					dmginfo:ScaleDamage(0.5)
					umsg.Start("Spin To", ent)
						umsg.Float(360)
						umsg.Float(1.8)
					umsg.End()
					ent.HasDoneARoll = false
				elseif ent:GetVelocity():Length() >= 1250 then
					return
				end
			end
	end
end
end
-- some functions NEED 3 agruments and functions names should never have " " arround them 
hook.Add("EntityTakeDamage", "DoARoll", DoARoll)

function team_1(ply)
ply:SetTeam(1)
ply:KillSilent()
ply:PrintMessage( HUD_PRINTTALK, ply:GetName().." has joined the Resistance" ) 


end
concommand.Add( "team_1", team_1 )

function team_2(ply)
ply:SetTeam(2)
ply:KillSilent()
ply:PrintMessage( HUD_PRINTTALK, ply:GetName().." has enlisted into the Universal Union's trans-human arms" )

end
concommand.Add( "team_2", team_2 )

--npcs spawns
function spawnrifleman(ply)
if ply:Team() == 1 then
local ent = ents.Create("npc_citizen")  
ent:SetKeyValue("citizentype", "3")
ent:SetKeyValue( "additionalequipment", "weapon_SMG1" )
local tr = ply:GetEyeTrace()
ent:SetPos(tr.HitPos)    
ent:Spawn()  
end
if ply:Team() == 2 then
local ent = ents.Create("npc_combine_s")
ent:SetKeyValue( "additionalequipment", "weapon_AR2" )
local tr = ply:GetEyeTrace()
ent:SetPos(tr.HitPos)
ent:Spawn()  
end
end
concommand.Add( "rnw_spawnrifleman", spawnrifleman )  

function spawnshotgunmedic(ply)
if ply:Team() == 1 then
local ent = ents.Create("npc_citizen")
ent:SetKeyValue("Model", "models/humans/Group03m/Female_01.mdl")  
ent:SetKeyValue("citizentype", "4")
ent:SetKeyValue("spawnflags", "155908")
ent:SetKeyValue( "additionalequipment", "weapon_pistol" )
local tr = ply:GetEyeTrace()
ent:SetPos(tr.HitPos)
ent:Spawn()  
end

if ply:Team() == 2 then
local ent = ents.Create("npc_combine_s")
ent:SetKeyValue( "additionalequipment", "weapon_shotgun" )
ent:SetKeyValue( "skin", "1" )
local tr = ply:GetEyeTrace() -- tr now contains a trace object
ent:SetPos(tr.HitPos) -- This positions the combine at the place our trace hit.
ent:Spawn() -- This method spawns the combine into the world
end
end
concommand.Add( "rnw_spawnshotgunmedic", spawnshotgunmedic )

function spawnbarricade(ply)
 if ply:Team() == 1 then
RunConsoleCommand( "gm_spawnvehicle", "Jeep" )
end
if ply:Team() == 2 then
RunConsoleCommand( "gm_spawn", "models/props_combine/combine_barricade_short01a.mdl" )
end
end
concommand.Add( "rnw_spawnbarricade", spawnbarricade )

function KillReason( victim, inflictor, killer )
     
    if !victim:IsPlayer() && !killer:IsPlayer() then
        return ""
    end
     
    local KT = killer:Team()
    local VT = victim:Team()
     
    local KR = "Unidentified"
     
    if KT != VT then
        KR = "Killed"
        victim:ChatPrint('You were killed!')
    else
        KR = "Betrayed"
        victim:ChatPrint('You were betrayed!')
    end
end
